package com.suse.service.admin.edu.controller;


import com.suse.common.config.response.R;
import com.suse.service.admin.edu.model.param.ChapterSaveParam;
import com.suse.service.admin.edu.model.param.ChapterUpdateParam;
import com.suse.service.admin.edu.service.ChapterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 章节 前端控制器
 * </p>
 *
 * @author 辜玉彬
 * @since 2022-08-11
 */
@Api(tags = "章节接口")
@RestController
@RequestMapping("/chapter")
public class ChapterController {

    @Resource
    private ChapterService chapterService;

    @ApiOperation(value = "通过课程ID获取章节列表")
    @GetMapping("/list/{courseId}")
    public R getChapterListByCourseId(@ApiParam(value = "课程ID") @PathVariable("courseId") String courseId) {
        return chapterService.getChapterListByCourseId(courseId);
    }

    @ApiOperation(value = "通过ID获取章节信息")
    @GetMapping("/info/{id}")
    public R getChapterInfoById(@PathVariable("id") String id) {
        return chapterService.getChapterInfoById(id);
    }

    @ApiOperation(value = "添加章节")
    @PostMapping("/save")
    public R saveChapter(@Valid @RequestBody ChapterSaveParam chapterSaveParam) {
        return chapterService.saveChapter(chapterSaveParam);
    }

    @ApiOperation(value = "通过修改章节")
    @PutMapping("/update")
    public R updateChapter(@Valid @RequestBody ChapterUpdateParam chapterUpdateParam) {
        return chapterService.updateChapter(chapterUpdateParam);
    }

    @ApiOperation(value = "通过ID删除章节")
    @DeleteMapping("/remove/{id}")
    public R removeChapterById(@PathVariable("id") String id) {
        return chapterService.removeChapterById(id);
    }

}

